package com.junqson.je.content.service;

import com.junqson.je.common.model.ApiResult;
import com.junqson.je.content.model.SectionModel;
import com.junqson.je.content.repo.SectionRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Descriptions
 * @Company
 * @Author Junqson
 * @Date 2020/2/10 23:38
 * @Version 1.0
 */
@Service
public class SectionService {
    @Autowired
    private SectionRepo sectionRepo;

    public ApiResult addSection(String name) {
        SectionModel model = sectionRepo.findBySectionName(name);
        if (model != null) {
            return ApiResult.error("板块重名");
        }
        model = new SectionModel();
        model.setSectionName(name);
        return ApiResult.success(sectionRepo.save(model));
    }

    public List<SectionModel> getAllSection() {
        return sectionRepo.findAll();
    }
}
